package demo;

import java.util.HashMap;

public class HashMapDeadlockExample {
    public static void main(String[] args) {
        // 创建两个Key对象，它们的hashCode相同，但不相等
        Key key1 = new Key(1);
        Key key2 = new Key(2);
        Key key3 = new Key(3);

        // 将这两个Key对象放入HashMap中
        HashMap<Key, String> map = new HashMap<>();
        map.put(key1, "value1");
        map.put(key2, "value2");
        map.put(key3, "value3");

        // 尝试获取key1对应的值
        String value = map.get(new Key(1));
        System.out.println(value);
    }

    static class Key {
        private int id;

        public Key(int id) {
            this.id = id;
        }

        @Override
        public int hashCode() {
            return 1;  // 所有Key对象的hashCode都相同
        }

        @Override
        public boolean equals(Object obj) {
            return false;  // 所有Key对象都不相等
        }
    }
}
